#!/bin/bash

set -e

cd "$(dirname $0)"

POTFILES_DIFF="$(diff -u0 <(grep -Pv '^#' POTFILES.in) <(cd .. && ls -1 *.cpp) || true)"
if [ -n "${POTFILES_DIFF}" ]
then
    echo "WARNING: po/POTFILES.in may need an update:"
    echo "[Begin proposed diff]"
    echo "${POTFILES_DIFF}"
    echo "[End proposed diff]"
fi

intltool-update --verbose --pot --gettext-package=tdlib-purple
# Translations are managed at https://www.transifex.com/tdlib-purple-developers/tdlib-purple/
# To update the .po files, download it from there, since intltool, msginit, and transifex
# produce slightly different files, and I'd like to avoid gigantic git diffs that only
# change indentation or similar things.

## Also, for some reason, the header generated by GNU intltool does not conform to
## What GNU.org says the header should look like.  So, let's fix it.
sed -ri -e 's,SOME DESCRIPTIVE TITLE,Translation (template) of tdlib-purple,' \
        -e "s,Copyright \(C\) YEAR THE PACKAGE'S COPYRIGHT HOLDER,Copyright (C) 2020 Arseniy Lartsev\n# Copyright (C) 2020 Ben Wiederhake," \
        -e 's,the same license as the PACKAGE package,the same license as the tdlib-purple package,' \
        -e 's.^#, fuzzy$.#.' \
        -e 's,Project-Id-Version: PACKAGE VERSION,Project-Id-Version: tdlib-purple,' \
        -e 's,Report-Msgid-Bugs-To: \\,Report-Msgid-Bugs-To: https://github.com/ars3niy/tdlib-purple/issues/new \\,' \
        -e 's,Content-Type: text/plain; charset=CHARSET,Content-Type: text/plain; charset=UTF-8,' \
        tdlib-purple.pot

# Later, add this, too:
#        -e 's.FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.Arseniy Lartsev <user@newline.site>, 2020.'
